#!/usr/bin/env bash
set -ex

if [ -n ${SKIP_VALIDATE} ]; then
    echo "skipping validation. continuing..."
    exit 0
fi

cd $(dirname $0)/..

GO=${GO-go}

echo Running validation

echo Running: go fmt
go fmt ./
echo Running: go vet
go vet ./

echo Running: golangci-lint
if ! command -v golangci-lint; then
    echo Skipping validation: no golangci-lint available
    exit
fi
golangci-lint run

go mod tidy

. ./scripts/version.sh

if [ -n "$DIRTY" ]; then
    echo Source dir is dirty
    git status --porcelain --untracked-files=no
    exit 1
fi
